package com.ruoyi.points.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.points.domain.BargainGroupListGrandson;
import com.ruoyi.points.mapper.BargainGroupListSonMapper;
import com.ruoyi.points.domain.BargainGroupListSon;
import com.ruoyi.points.service.IBargainGroupListSonService;

/**
 * 主页展示Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-05
 */
@Service
public class BargainGroupListSonServiceImpl implements IBargainGroupListSonService
{
    @Autowired
    private BargainGroupListSonMapper bargainGroupListSonMapper;

    /**
     * 查询主页展示
     *
     * @param id 主页展示主键
     * @return 主页展示
     */
    @Override
    public BargainGroupListSon selectBargainGroupListSonById(Long id)
    {
        return bargainGroupListSonMapper.selectBargainGroupListSonById(id);
    }

    /**
     * 查询主页展示列表
     *
     * @param bargainGroupListSon 主页展示
     * @return 主页展示
     */
    @Override
    public List<BargainGroupListSon> selectBargainGroupListSonList(BargainGroupListSon bargainGroupListSon)
    {
        return bargainGroupListSonMapper.selectBargainGroupListSonList(bargainGroupListSon);
    }

    /**
     * 新增主页展示
     *
     * @param bargainGroupListSon 主页展示
     * @return 结果
     */
    @Transactional
    @Override
    public int insertBargainGroupListSon(BargainGroupListSon bargainGroupListSon)
    {
        int rows = bargainGroupListSonMapper.insertBargainGroupListSon(bargainGroupListSon);
        insertBargainGroupListGrandson(bargainGroupListSon);
        return rows;
    }

    /**
     * 修改主页展示
     *
     * @param bargainGroupListSon 主页展示
     * @return 结果
     */
    @Transactional
    @Override
    public int updateBargainGroupListSon(BargainGroupListSon bargainGroupListSon)
    {
        return bargainGroupListSonMapper.updateBargainGroupListSon(bargainGroupListSon);
    }

    /**
     * 批量删除主页展示
     *
     * @param ids 需要删除的主页展示主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBargainGroupListSonByIds(Long[] ids)
    {
        bargainGroupListSonMapper.deleteBargainGroupListGrandsonByPids(ids);
        return bargainGroupListSonMapper.deleteBargainGroupListSonByIds(ids);
    }

    /**
     * 删除主页展示信息
     *
     * @param id 主页展示主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBargainGroupListSonById(Long id)
    {
        bargainGroupListSonMapper.deleteBargainGroupListGrandsonByPid(id);
        return bargainGroupListSonMapper.deleteBargainGroupListSonById(id);
    }

    /**
     * 新增${subTable.functionName}信息
     *
     * @param bargainGroupListSon 主页展示对象
     */
    public void insertBargainGroupListGrandson(BargainGroupListSon bargainGroupListSon)
    {
        List<BargainGroupListGrandson> bargainGroupListGrandsonList = bargainGroupListSon.getBargainGroupListGrandsonList();
        Long id = bargainGroupListSon.getId();
        if (StringUtils.isNotNull(bargainGroupListGrandsonList))
        {
            List<BargainGroupListGrandson> list = new ArrayList<BargainGroupListGrandson>();
            for (BargainGroupListGrandson bargainGroupListGrandson : bargainGroupListGrandsonList)
            {
                bargainGroupListGrandson.setPid(id);
                list.add(bargainGroupListGrandson);
            }
            if (list.size() > 0)
            {
                bargainGroupListSonMapper.batchBargainGroupListGrandson(list);
            }
        }
    }
}
